package com.wsoft.dc.controller;

import cn.hutool.core.util.ObjUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.wsoft.dc.constant.ConfigConstant;
import com.wsoft.dc.query.dc.DcListQuery;
import com.wsoft.dc.query.dc.DcPortalQuery;
import com.wsoft.dc.service.IDcService;
import com.wsoft.dc.vo.ConfigEntityVO;
import com.wsoft.response.ResponseResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @Author z001
 * @Date 2024/12/18 15:36
 */
@RestController
@Tag(name = "获取待办数据")
@RequestMapping("/dc")
public class DcController {

    @Resource
    private IDcService dcService;

    @Operation(summary = "查询待办列表", description = "查询待办列表")
    @PostMapping("/list")
    public ResponseResult list(@RequestBody DcListQuery query) {
        Map<String, Object> map = dcService.dcList(query, true);
        //过滤掉 title属性  ==> 前端写死,后端不返回
        Object object = map.get("searchAttributesList");
        if(ObjUtil.isEmpty(object)){
            return ResponseResult.success(map);
        }
        List<ConfigEntityVO> list = JSONArray.parseArray(JSON.toJSONString(object), ConfigEntityVO.class);
        List<ConfigEntityVO> collect = list.stream().filter(item -> !item.getAttribute().equals(ConfigConstant.DEFAULT_TITLE)).collect(Collectors.toList());
        map.put("searchAttributesList",collect);
        return ResponseResult.success(map);
    }

    @Operation(summary = "首页弹框-查询待办个数", description = "首页弹框-查询待办个数")
    @PostMapping("/homeCount")
    public ResponseResult homeCount() {
        return ResponseResult.success(dcService.homeCount());
    }

    @Operation(summary = "门户-查询待办个数", description = "门户-查询待办个数")
    @PostMapping("/portalCount")
    public ResponseResult portalCount(@RequestBody DcPortalQuery query) {
        return ResponseResult.success(dcService.portalCount(query));
    }

}
